<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>-->
    <!--<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>-->
    <!--<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>-->
    <!--[endif]-->

    <script type="text/javascript" src="../../common/js/public.js"></script>
    <script type="text/javascript" src="../../common/js/publicUtils.js"></script>
    <!-- <script type="text/javascript" src="../js/tokenUtils.js"></script>-->
</head>
<body>
<div class="layui-fluid" id="flowDiv" onload="onLoad()">
    <div class="zTreeBackground left" style="float: left;width:400px">
        <div class="titlediv">
            <p style="text-align:right;background-color:white;line-height: 30px">
                组织信息<i class="layui-icon layui-icon-refresh" style="margin-left: 36%" onclick="refreshRoot()"></i>&ensp;&ensp;
            </p>

        </div>
        <div class="searchdiv" >
            <div class="layui-input-inline" style="width:100%">
                <input type="text" id="search" name="keyword" autocomplete="off" class="layui-input" placeholder="请输入名称" style="height: 30px"/>
                <i class="layui-icon layui-icon-search" style="position: absolute;top:8px;right: 8px;" onclick="searchByName()"></i>
            </div>
        </div>
        <div class="ztreediv" id="ztreediv">
            <div class="ztreeuldiv">
                <ul id="treeStructure" class="ztree"></ul>
            </div>
        </div>
    </div>
</div>
<script>
    var node,projectForMoveTo;
    $(document).ready(function() {
        initTree("#treeStructure");
    })

    window.onload = getContentSize;
    window.onresize = getContentSize;

    /**
     * 页面自适应
     */
    function getContentSize() {
        var wh = document.documentElement.clientHeight;
        var eh = 30;
        ch = (wh - eh) + "px";
        document.getElementById( "flowDiv" ).style.height = ch;
        document.getElementById( "ztreediv" ).style.height = (wh - eh - 50)+"px";
        document.body.style.height = (wh)+"px";
    }

    function inintData(val){
        projectForMoveTo = val;
    }

    var setting = {
        check: {
            //enable: true,
            chkboxType: { "Y": "s", "N": "s" }
        },
        edit:{
            enable: false
        },
        async: {
            enable: true,
            url: publicUrl+"project/getProjectsForTree",
            dataFilter: formatedata,
            headers: {"Authorization":getData("Authorization")},
            autoParam: ["id","type"]
        },
        data: {
            simpleData: {
                enable: true,
                idKey:"id",
                pIdKey:"pid",
                isParent:"parent",
                rootPid:"",
                type:"type"

            },
            key: {
                isParent:"parent",
                url: "xUrl",
                icon:"xIcon",
                level:"orgLevel",
                name:"shortName"
            }
        },
        callback: {
            beforeClick: beforeClick,
            onClick: zTreeOnClick
        }
    };

    /* *
     * @Author bxf
     * @Description 刷新树
     * @Date 11:16 2019/8/28
     * @param null
     * @return
     */
    function refreshRoot(){
        initTree("#treeStructure");
    }

    function searchByName(){
        var search = $("#search").val();
        if(!search){
            return ;
        }
        loadTree("#treeStructure");
    }
    /* *
     * @Author bxf
     * @Description 加载树
     * @Date 14:31 2019/8/28
     * @param null
     * @return
     */
    function loadTree(id){
        $(id).html('');
        publicAjax (null,'orgstation/getProjectsForTree',{"name":$("#search").val(),"stationFlag":2},false,null,function(data){
            zTreeObj = $.fn.zTree.init($(id),setting, changeIcon(data.data));
            zTreeObj.expandAll(true);
        })
    }

    function formatedata(treeId,parentNode,responseData) {
        return changeIcon(formatTreeParseData(treeId,parentNode,responseData,null));
    }

    function initTree(id){
        $(id).html('');
        publicAjax(null,"company/getByPersonId",{},false,null,function(data){
            zTreeObj = $.fn.zTree.init($(id),setting, changeIcon(data.data));
            /* console.log(zTreeObj);
             //让第一个父节点展开
             var rootNode_0 = zTreeObj.getNodeByParam('pid',0,null);
             zTreeObj.expandNode(rootNode_0, true, false, false, false);*/
        })
    }

    // zTree 的参数配置，深入使用请参考 API 文档（setting 配置详解）

    function beforeClick(treeId, treeNode, clickFlag) {
        if(treeNode.type!=4){
            layer.msg("请选择项目部",{time:500});
            return false;
        }
    }

    // zTree 的参数配置，深入使用请参考 API 文档（setting 配置详解）
    function zTreeOnClick(event, treeId, treeNode, clickFlag) {
        /*parentType = '';
        parentId = '';
        parentName='';*/
        node = treeNode;

//		window.frames["iframe_ID"].window.getInfo(parentId);
    }

    function moveTo(){
        var result;
        if (typeof(node) != "undefined" && node != "") {
            if(node.type == 4){
                if (node.id == window.parent.nodeSelected.id) {
                    layer.alert("非法移动");
                    return false;
                }
                var url = 'project/moveTo';
                var form = {
                    id: projectForMoveTo[0].id,
                    orgId: node.id
                };

                publicAjax(null,url,form,false,null,function (r) {
                    if(r.code==2000){
                        laysuccess("移动成功",null);
                        result = r;
                    }else{
                        layerror(r.msg,null);
                        result = r;
                    }
                })
                return result;
            }else{
                layer.alert("请选择项目部");
                return false;
            }
        } else {
            layer.alert("请选择组织");
            return false;
        }
    }
</script>

</body>
</html>